package fredgolm;

public class Tester {


    public static void legandreTEST() {

       int basisDim = 20;

       Solver s1 = new Solver(null, null, basisDim);

       double[] polinom = s1.getLegandrePolynom(10);
        for(int i=0; i<polinom.length; i++) {
              System.out.println(polinom[i] + " ");
          }
          System.out.println();

   }

   /**
    * @param args the command line arguments
    */
   public static void main(String[] args) {

       legandreTEST();
       

       int N = 10000; //╤ç╨╕╤ü╨╗╨╛ ╤â╨╖╨╗╨╛╨▓
       double a = -1;
       double b = 1;
       int basisDim = 4;

       double[] Args = new double[N];
       double[] f = new double[N];
       double h = Math.abs(b-a)/(double)(N-1);

       double maxError = 0;
       //double minError = 1000;
 

       for(int i=0; i<N; i++) {
           Args[i] = a + i*h;
           //f[i] = Math.sin((a + i*h)*Math.PI*0.5);
           //f[i] = Math.exp(a+i*h);
           f[i]=(a+i*h)*(a+i*h);
           //f[i] = 1/((a+i*h)*(a+i*h) - 5);
           //f[i] = Math.abs(a+i*h)-1;
          // f[i] = Math.sin(Args[i]);
           //f[i] = 1/(Args[i] + 2);
           //f[i] = 1/
       }


        double[] argsOnUnitSection;
        if(a < -1 || b > 1) {
             argsOnUnitSection = Args.clone();
             for(int i=0; i<argsOnUnitSection.length; i++) {
                  argsOnUnitSection[i] = 2 * argsOnUnitSection[i]/(b - a) + (a + b)/(a - b);
             }
        } else {
           argsOnUnitSection = Args;
        }

       Solver s = new Solver(argsOnUnitSection, f, basisDim);


      double[] resPolinom = s.getPolinom();
     
       
       for(int i = 0; i < f.length; ++i) {
            System.out.print(Args[i] + "    ");  System.out.print(f[i] + "    ");

            double res =s.get_F(resPolinom, argsOnUnitSection[i]);
            System.out.print(res + "    ");
            System.out.print(f[i] - res);
            System.out.println(" ");

            maxError = Math.max(Math.abs(f[i] - res), maxError);
         //   minError = Math.min(Math.abs(f[i] - res), minError);

       }
        System.out.println("Max Error: " + maxError);
       // System.out.println("Min Error: " + minError);

   }


  

} 